package com.atguigu.yygh.cmn.controller;

import com.atguigu.yygh.cmn.service.DictService;
import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.model.cmn.Dict;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "数据字典")
@RestController
@RequestMapping("/admin/cmn/dict")
@CrossOrigin
public class DictController {

    @Autowired
    private DictService dictService;

    @ApiOperation(value = "根据上节点查询当前字节点的数据列表")
    @GetMapping("findChildDate/{id}")
    public Result findChildDate(@PathVariable Long id) {
        List<Dict> childDate = dictService.findChildDate(id);
        return Result.ok(childDate);
    }

    @ApiOperation(value = "导出提交")
    @GetMapping("exportData")
    public void exportData(HttpServletResponse response) {
        dictService.exportDictData(response);
    }


    @ApiOperation(value = "导入提交")
    @PostMapping("importData")
    public Result importData(MultipartFile file) {
        dictService.importData(file);
        return Result.ok();
    }

    @ApiOperation(value = "医院等级")
    @GetMapping("getName/{dictCode}/{value}")
    public String getName(@PathVariable String dictCode,@PathVariable String value){
        String name = dictService.getDictName(dictCode,value);
        return name;
    }
    @ApiOperation(value = "地区")
    @GetMapping("getName/{value}")
    public String getName(@PathVariable String value){
        String name = dictService.getDictName("",value);
        return name;
    }

//    //3 条件查询带分页
//    @ApiOperation(value = "分页查询")
//    @PostMapping("findPageHospSet/{current}/{limit}")
//    public Result findPageHospSet(@PathVariable long current,
//                                  @PathVariable long limit,
//                                  @RequestBody
//                                          (required = false) HospitalSetQueryVo hospitalSetQueryVo) {
//        //创建page对象，传递当前页，每页记录数
//        Page<HospitalSet> page = new Page<>(current,limit);
//        //构建条件
//        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
//        String hosname = hospitalSetQueryVo.getHosname();//医院名称
//        String hoscode = hospitalSetQueryVo.getHoscode();//医院编号
//        if(!StringUtils.isEmpty(hosname)) {
//            wrapper.like("hosname",hospitalSetQueryVo.getHosname().trim());
//        }
//        if(!StringUtils.isEmpty(hoscode)) {
//            wrapper.eq("hoscode",hospitalSetQueryVo.getHoscode().trim());
//        }
//        //调用方法实现分页查询
//        Page<HospitalSet> pageHospitalSet = hospitalSetService.page(page, wrapper);
//        //返回结果
//        return Result.ok(pageHospitalSet);
//    }


}


